/*
 * @Author: fanzhiwei
 * @Date: 2024-07-12 09:30:16
 * @LastEditors: fanzhiwei
 * @LastEditTime: 2024-07-12 10:18:04
 * @FilePath: /common-web-ui/src/utils/formatRouter.js
 * @Description:
 */
import Layout from "@/layout";
function loadView(view) {
  return (resolve) => require([`@/views/pages/${view}`], resolve);
}

export function formatRouter(asyncRouterMap) {
  return asyncRouterMap.filter((route) => {
    if (route.component) {
      // Layout组件特殊处理
      if (route.component === "Layout") {
        route.component = Layout;
      } else {
        route.component = loadView(route.component);
      }

      if (route.meta?.isKeepAlive === undefined) {
        route.meta.isKeepAlive = true;
      }
    }
    if (route.children && route.children.length) {
      route.children = formatRouter(route.children);
    }
    return true;
  });
}
